package site.yunnong.atvris.portal.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import site.yunnong.atvris.common.api.ResultVO;
import site.yunnong.atvris.common.dto.UserUpdateParam;
import site.yunnong.atvris.portal.service.UserManageService;
import site.yunnong.atvris.service.vo.UserInfoVO;

/**
 * @author JinghaoZhang
 * @date 2021年-04月-07日
 */
@Slf4j
@Api(tags = "用户管理")
@RestController
@RequestMapping("/account")
public class UserController {

    @Autowired
    private UserManageService userManageService;

    @ApiOperation("获取个人信息")
    @GetMapping("/info")
    public ResultVO info() {
        UserInfoVO result = userManageService.getUserInfo();
        return new ResultVO().success(result);
    }

    @ApiOperation("根据用户唯一标识查询用户信息")
    @GetMapping("/query-info-by-uuid")
    public ResultVO queryInfoByUuid(@RequestParam("uuid") Long uuid) {
        UserInfoVO result = userManageService.queryInfoByUuid(uuid);
        return new ResultVO().success(result);
    }
    
    @ApiOperation("更新头像")
    @PostMapping("/update-avatar")
    public ResultVO updateAvatar(@RequestParam("fileName") String fileName) {
        userManageService.updateAvatar(fileName);
        return new ResultVO().success();
    }
    
    @ApiOperation("更新个人信息")
    @PostMapping("/update-info")
    public ResultVO updateInfo(@RequestBody UserUpdateParam param) {
        userManageService.updateInfo(param);
        return new ResultVO().success();
    }
    
    @ApiOperation("昵称是否已被他人使用")
    @GetMapping("/is-nickname-used-by-others")
    public ResultVO isNicknameUsedByOthers(@RequestParam String nickname) {
        return new ResultVO().success(userManageService.isNicknameUsedByOthers(nickname));
    }
    
    @ApiOperation("查询教育水平枚举")
    @GetMapping("/query-education-enum")
    public ResultVO queryEducationEnumList() {
        return new ResultVO().success(userManageService.queryEducationEnumList());
    }
}
